//
//  VC_Mine.m
//  yjw-winner
//
//  Created by Kae on 2018/8/30.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "VC_Mine.h"
#import "VC_Setting.h"
#import "VC_BoughtRecord.h"
#import "VC_CollectTion.h"
#import "VC_Signup.h"
#import "VC_UserInfo.h"

#define CELL_IDENTIFIER_DEFAULT @"cell_indetifier_default"
#define CELL_IDENTIFIER_BUTTON @"cell_indetifier_button"
#define CELL_IDENTIFIER_HEADER @"cell_indetifier_header"

@interface VC_Mine () <UITableViewDataSource, UITableViewDelegate>{

}
@property (strong, nonatomic) IBOutlet UITableView *tableView;


@property (nonatomic, strong) NSArray *cellArray;
@end

@implementation VC_Mine
- (void)awakeFromNib {
    [super awakeFromNib];
    
}
- (NSArray *)cellArray {
    if (!_cellArray) {
        Model_MineCell *model1 = [[Model_MineCell alloc] init];
        Model_MineCell *model2 = [[Model_MineCell alloc] init];
        Model_MineCell *model3 = [[Model_MineCell alloc] init];
        Model_MineCell *model4 = [[Model_MineCell alloc] init];
        Model_MineCell *model5 = [[Model_MineCell alloc] init];
        Model_MineCell *model6 = [[Model_MineCell alloc] init];
        Model_MineCell *model7 = [[Model_MineCell alloc] init];
        
        model1.icon = @"un_audio_icon";
        model1.title = @"name";
        model1.detail = @"暂未加入班级";
        model1.cellIdentifier = CELL_IDENTIFIER_HEADER;
        model1.cellAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        model1.cellHeight = 86.0;
        
        model2.icon = @"";
        model2.title = @"";
        model2.detail = @"邀请好友领福利";
        model2.cellIdentifier = CELL_IDENTIFIER_BUTTON;
        model2.cellAccessoryType = UITableViewCellAccessoryNone;
        model2.cellHeight = 84.0;
        
        model3.icon = @"mine_cell_icon_notes";
        model3.title = @"购买记录";
        model3.cellIdentifier = CELL_IDENTIFIER_DEFAULT;
        model3.cellAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        model3.cellHeight = 49.0;
        
        model4.icon = @"mine_cell_icon_consult";
        model4.title = @"电话咨询";
        model4.cellIdentifier = CELL_IDENTIFIER_DEFAULT;
        model4.cellAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        model4.cellHeight = 49.0;
        
        model5.icon = @"mine_cell_icon_signup";
        model5.title = @"我的报名";
        model5.cellIdentifier = CELL_IDENTIFIER_DEFAULT;
        model5.cellAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        model5.cellHeight = 49.0;
        
        model6.icon = @"mine_cell_icon_collect";
        model6.title = @"我的收藏";
        model6.cellIdentifier = CELL_IDENTIFIER_DEFAULT;
        model6.cellAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        model6.cellHeight = 49.0;
        
        model7.icon = @"mine_cell_icon_setting";
        model7.title = @"设置";
        model7.cellIdentifier = CELL_IDENTIFIER_DEFAULT;
        model7.cellAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        model7.cellHeight = 49.0;
        
        
        
        model1.selName = NSStringFromSelector(@selector(mineUserInfo:));
        model2.selName = NSStringFromSelector(@selector(mineInvite:));
        model3.selName = NSStringFromSelector(@selector(mineLogs:));
        model4.selName = NSStringFromSelector(@selector(mineConsult:));
        model5.selName = NSStringFromSelector(@selector(mineSignup:));
        model6.selName = NSStringFromSelector(@selector(mineCollect:));
        model7.selName = NSStringFromSelector(@selector(mineSetting:));
        
        _cellArray = @[@[model1],
                       @[model2],
                       @[model3, model4],
                       @[model5, model6],
                       @[model7]];
    }
    return _cellArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [UIView new];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark --mark UITableViewDataSource UITableViewDelegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    Model_MineCell *model = self.cellArray[indexPath.section][indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:model.cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:model.cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.accessoryType = model.cellAccessoryType;
    cell.imageView.image = [UIImage imageNamed:model.icon];
    cell.textLabel.text = model.title;
    cell.detailTextLabel.text = model.detail;
    
    if (indexPath.section == 0) {
        CGSize itemSize = CGSizeMake(55.0f, 55.0f);
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
        CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
        [cell.imageView.image drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        cell.imageView.layer.cornerRadius = itemSize.width * 0.5;
        cell.imageView.layer.masksToBounds = YES;
    }
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.cellArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.cellArray[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    Model_MineCell *model = self.cellArray[indexPath.section][indexPath.row];
    return model.cellHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return  2.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Model_MineCell *model = self.cellArray[indexPath.section][indexPath.row];
    SEL sel = NSSelectorFromString(model.selName);
    if ([self respondsToSelector:sel]) {
        [self performSelector:sel withObject:@{@"token":@"这是个token"} afterDelay:0.0f];
    }
}





#pragma mark --mark selector

- (void)mineUserInfo:(id)info {
    VC_UserInfo *vc = [[VC_UserInfo alloc] init];
    vc.title = @"个人资料";
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)mineInvite:(id)info {
    
}

/**
 购买记录
 @param info info
 */
- (void)mineLogs:(id)info {
    VC_BoughtRecord *vc = [[VC_BoughtRecord alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    vc.title = @"购买记录";
    [self.navigationController pushViewController:vc animated:YES];
}

/**
 电话咨询

 @param info info
 */
- (void)mineConsult:(id)info {
    [MBProgressHUD showSuccess:@"电话咨询界面"];
}
- (void)mineSignup:(id)info {
    VC_Signup *vc = [[VC_Signup alloc] init];
    vc.title = @"我的报名";
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)mineCollect:(id)info {
    VC_CollectTion *vc = [[VC_CollectTion alloc] init];
    vc.title = @"我的收藏";
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)mineSetting:(id)info {
    NSLog(@"%@", [(NSDictionary *)info valueForKey:@"token"]);
    VC_Setting *setting = [VC_Setting instance];
    [self.navigationController pushViewController:setting animated:YES];
}


@end
